import QtQuick 2.14
import QtQuick.Controls 2.14
import QtQuick.Layouts 1.14

Dialog {
    id: confirmDialog
    
    property string confirmTitle: ""
    property string confirmMessage: ""
    property string confirmCallback: ""
    property string acceptText: "确认"
    property string rejectText: "取消"
    
    signal confirmed()
    signal rejected()
    
    title: confirmTitle
    modal: true
    standardButtons: Dialog.NoButton
    
    width: Math.min(400, parent.width * 0.8)
    height: Math.min(180, parent.height * 0.5)
    
    anchors.centerIn: parent
    
    background: Rectangle {
        color: "white"
        border.color: "#E0E0E0"
        border.width: 1
        radius: 8
    }
    
    contentItem: ColumnLayout {
        spacing: 20
        
        // 警告图标和消息
        RowLayout {
            Layout.fillWidth: true
            spacing: 15
            
            Rectangle {
                width: 40
                height: 40
                radius: 20
                color: "#FF9800"
                
                Text {
                    anchors.centerIn: parent
                    text: "?"
                    font.pixelSize: 20
                    font.bold: true
                    color: "white"
                }
            }
            
            Text {
                text: confirmMessage
                font.pixelSize: 14
                color: "#212121"
                wrapMode: Text.WordWrap
                Layout.fillWidth: true
            }
        }
        
        // 按钮区域
        RowLayout {
            Layout.fillWidth: true
            
            Item {
                Layout.fillWidth: true
            }
            
            Button {
                text: rejectText
                onClicked: {
                    confirmDialog.rejected()
                    confirmDialog.close()
                }
            }
            
            Button {
                text: acceptText
                highlighted: true
                onClicked: {
                    confirmDialog.confirmed()
                    confirmDialog.close()
                    
                    // 执行回调
                    if (confirmCallback !== "" && typeof qmlBridge !== 'undefined') {
                        // 这里可以根据callback执行相应的操作
                        console.log("Executing callback:", confirmCallback)
                    }
                }
            }
        }
    }
    
    function show(title, message, callback, accept, reject) {
        confirmTitle = title || "确认操作"
        confirmMessage = message || "您确定要执行此操作吗？"
        confirmCallback = callback || ""
        acceptText = accept || "确认"
        rejectText = reject || "取消"
        open()
    }
}